<template>
  <div v-if="localStorage.getItem('jwt').getType==2">
    <el-breadcrumb separator-class="el-icon-arrow-right" style="font-size: 16px;">
      <el-breadcrumb-item :to="{ path: '/' }">
        <i class="el-icon-s-promotion"></i> 用户管理
      </el-breadcrumb-item>
      <el-breadcrumb-item>用户升级</el-breadcrumb-item>
    </el-breadcrumb>

    <el-divider></el-divider>

    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="id" label="ID" width="80" align="center"></el-table-column>
      <el-table-column prop="name" label="名称" width="230" header-align="center"
                       :show-overflow-tooltip="true"></el-table-column>
      <el-table-column prop="pwd" label="密码" header-align="center"
                       :show-overflow-tooltip="true"></el-table-column>
    </el-table>
    <el-dialog title="用户升级" :visible.sync="dialogFormVisible">
      <el-form :model="editForm">
        <el-form-item label="名称" :label-width="formLabelWidth">
          <el-input v-model="editForm.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="密码" :label-width="formLabelWidth">
          <el-input v-model="editForm.description" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitEdit()">确 定</el-button>
      </div>
    </el-dialog>
  </div>

</template>

<script>
export default {
  data(){
    return {
      tableData: [],
      dialogFormVisible: false,
      editForm: {
        name: '',
        pwd: ''
      },
      formLabelWidth: '120px'
    }
  },
  methods:{
    submitEdit() {
      let url = 'http://localhost:8888/user/be-saler';
      console.log('url = ' + url);
      let formData = this.qs.stringify(this.editForm);
      console.log('formData = ' + formData);

      this.axios.post(url, formData).then((response) => {
        let responseBody = response.data;
        if (responseBody.state == 20000) {
          this.$message({
            message: '修改用户成功！',
            type: 'success'
          });
          this.dialogFormVisible = false;
          this.loadUserList();
        } else if (responseBody.state == 40400) {
          this.$message.error(responseBody.message);
          this.dialogFormVisible = false;
          this.loadAlbumList();
        } else if (responseBody.state == 40900) {
          this.$message.error(responseBody.message);
        }
      })
    }
  }

}
</script>

<style scoped>

</style>